package io.xuan.modules.admin.controller;

import io.xuan.common.utils.PageUtils;
import io.xuan.common.utils.R;
import io.xuan.modules.app.entity.CarInfoEntity;
import io.xuan.modules.app.entity.CarLineEntity;
import io.xuan.modules.app.entity.CarStationEntity;
import io.xuan.modules.app.service.CarInfoService;
import io.xuan.modules.app.service.CarLineService;
import io.xuan.modules.app.service.CarStationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

@Api(tags = "管理端——车辆管理")
@RestController
@RequestMapping("admin/car")
public class AboutCarController {
    @Autowired
    private CarLineService carLineService;

    @Autowired
    private CarStationService carStationService;

    @Autowired
    private CarInfoService carInfoService;


    @GetMapping("/list")
    @ApiOperation("路线列表")               //所有线路的列表
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = carLineService.queryPage(params);

        return R.ok().put("page", page);
    }


    @GetMapping("/info/{carLine}")
    @ApiOperation("路线详情")
    public R info(@PathVariable("cateId") Integer cateId) {
        CarLineEntity carLine = carLineService.getById(cateId);

        return R.ok().put("carLine", carLine);
    }


    @PostMapping("/save")
    @ApiOperation("路线保存")
    public R save(@RequestBody CarLineEntity carLine) {

        carLineService.saveCarLine(carLine);

        return R.ok();
    }


    @PostMapping("/update")
    @ApiOperation("路线修改")
    public R update(@RequestBody CarLineEntity carLine) {
        carLineService.updateCarLine(carLine);

        return R.ok();
    }


    @PostMapping("/delete")
    //@RequiresPermissions("admin:carLine:delete")
    @ApiOperation("分类删除")
    public R delete(@RequestBody Integer[] carLine) {
        carLineService.deleteByIdList(Arrays.asList(carLine));

        return R.ok();
    }


    /////////////////info
    @GetMapping("/infoList")
    @ApiOperation("路线列表")
    public R infoList(@RequestParam Map<String, Object> params) {
        PageUtils page = carInfoService.queryPage(params);

        return R.ok().put("page", page);
    }


    @GetMapping("/carInfoInfo/{carLine}")
    @ApiOperation("路线详情")
    public R carInfoInfo(@PathVariable("cateId") Integer cateId) {
        CarInfoEntity carInfo = carInfoService.getById(cateId);

        return R.ok().put("carInfo", carInfo);
    }


    @PostMapping("/infoSave")
    //@RequiresPermissions("admin:carLine:save")
    @ApiOperation("路线保存")
    public R infoSave(@RequestBody CarInfoEntity carInfo) {
        carInfoService.saveCarInfo(carInfo);

        return R.ok();
    }


    @PostMapping("/infoUpdate")
    //@RequiresPermissions("admin:carLine:update")
    @ApiOperation("路线修改")
    public R infoUpdate(@RequestBody CarInfoEntity carInfo) {
        carInfoService.updateCarInfo(carInfo);

        return R.ok();
    }


    @PostMapping("/infoDelete")
    //@RequiresPermissions("admin:carLine:delete")
    @ApiOperation("分类删除")
    public R infoDelete(@RequestBody Integer[] carInfo) {
        carInfoService.deleteByIdList(Arrays.asList(carInfo));

        return R.ok();
    }

    ///////////////station
    @GetMapping("/stationList")
    //@RequiresPermissions("admin:carLine:list")        有权限才能访问
    @ApiOperation("路线列表")
    public R stationList(@RequestParam Map<String, Object> params) {
        PageUtils page = carStationService.queryPage(params);

        return R.ok().put("page", page);
    }


    @GetMapping("/stationInfo/{carStation}")
    //@RequiresPermissions("admin:carLine:info")
    @ApiOperation("路线详情")
    public R stationInfo(@PathVariable("cateId") Integer cateId) {
        CarStationEntity carStation = carStationService.getById(cateId);

        return R.ok().put("carStation", carStation);
    }


    @PostMapping("/stationSave")
    //@RequiresPermissions("admin:carLine:save")
    @ApiOperation("路线保存")
    public R stationSave(@RequestBody CarStationEntity carStation) {

        carStationService.saveCarStation(carStation);

        return R.ok();
    }


    @PostMapping("/stationUpdate")
    //@RequiresPermissions("admin:carLine:update")
    @ApiOperation("路线修改")
    public R stationUpdate(@RequestBody CarStationEntity carStation) {
        carStationService.updateCarStation(carStation);

        return R.ok();
    }


    @PostMapping("/stationDelete")
    //@RequiresPermissions("admin:carLine:delete")
    @ApiOperation("分类删除")
    public R stationDelete(@RequestBody Integer[] carStation) {
        carStationService.deleteByIdList(Arrays.asList(carStation));

        return R.ok();
    }


}
